home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 1527 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.5 KB

  1. Path: kettle.magna.com.au!news
  2. From: peter@magna.com.au
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: STL deque compile warning
  5. Date: 11 Jan 1996 14:33:08 GMT
  6. Organization: MAGNADATA Internet Services
  7. Message-ID: <4d3734$mdc@kettle.magna.com.au>
  8. References: <4cvf0n$jq@maureen.teleport.com>
  9. NNTP-Posting-Host: enterprise.magna.com.au
  10. X-Newsreader: AIR News 3.X (SPRY, Inc.)
  11.  
  12. >   Jeff Grossman <grossman@teleport.com> writes:
  13. >  Using MSVC4 (and the STL on MS's CD-ROM), this simple program,
  14. >  
  15. >  #include <deque.h>
  16. >  
  17. >  class foo
  18. >  {
  19. >      int        n1;
  20. >      int        n2;
  21. >  };
  22. >  
  23. >  int main ()
  24. >  {
  25. >      deque< foo >    dFoo;
  26. >  
  27. >      return 0;
  28. >  }
  29. >  
  30. >  
  31. >  generates the following warnings:
  32. >  
  33. >  deque.h(106) : warning C4146: unary minus operator applied to
  34. >                                unsigned type, result still unsigned
  35. >  deque.h(187) : warning C4146: unary minus operator applied to
  36. >                                unsigned type, result still unsigned
  37. >  deque.h(455) : warning C4018: '>' : signed/unsigned mismatch
  38. >  deque.h(469) : warning C4018: '>' : signed/unsigned mismatch
  39. >  
  40. >  
  41. >  Does anyone know STL well enough to understand the significance of these
  42. >  warnings?
  43. >  
  44. >  I've looked at the offending code, but I'm very new to STL, and I can't 
  45. >  tell if these warnings are indicative of a true problem or not.
  46. >  
  47. >  
  48. >  TIA,
  49. >  Jeff
  50. >  
  51.  
  52. I'm only just starting on STL so here goes my $0.02.
  53.  
  54. line 106 warning refers to the following
  55.  
  56.     difference_type num_node_to_jump = offset >= 0
  57.     ? offset / buffer_size
  58.     : -((-offset + buffer_size - 1) / buffer_size);
  59.  
  60. where 
  61.     typedef int ptrdiff_t;                             // from <stddef.h>
  62.  
  63.     typedef ptrdiff_t difference_type; // from <stl\defalloc.h>
  64.  
  65.     difference_type  offset;
  66.     size_t                     buffer_size;         // which is an unsigned from <stddef.h>
  67.  
  68. Now the result of the offset + buffer_size goes through *integral promotion*   (ARM 4.1).
  69. The result of unary negation of the unsigned is still an unsigned.
  70.  
  71. Ditto line 187.
  72.  
  73. Line 455 refers to
  74.  
  75.         if (n > position - old_begin)
  76.  
  77. where
  78.     size_t       n;                        // hence an unsigned.
  79.     iterator     position;
  80.     iterator     old_begin;
  81.  
  82. now the result of  position - old_begin must convert to an int (signed).
  83.  
  84. I do not know if iterator is signed (being a pointer I would think that it is 
  85. unsigned), or if the result of subtraction of two unsigned values converts
  86. to an int.
  87.  
  88.  
  89. I did also compile your test program using the STL<ToolKit> from 
  90. ObjectSpace and it did not have any problem.
  91.  
  92. Hope this helps a little.
  93.  
  94. Cheers, 
  95. Peter J Brock
  96.  
  97.